package com.lvcoding.resourceserver.controller;

import com.lvcoding.common.SecurityUtil;
import com.lvcoding.common.User;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;

@RestController
public class HelloController {

    @GetMapping("admin")
    @PreAuthorize("hasAnyAuthority('u:admin:view')")
    public String admin(Principal principal) {
        System.out.println("principal = " + principal);
        User user = SecurityUtil.getCurrentUser();
        System.out.println(user.getUsername());
        System.out.println(user.getPassword());
        System.out.println(user.getAuthorities());
        return "我是admin";
    }

    @GetMapping("common")
    @PreAuthorize("hasAnyAuthority('u:common:view')")
    public String common() {
        return "我是common";
    }
}
